//
//  Utilities.m
//  bestone-qt
//
//  Created by yexiaodong on 12-10-18.
//  Copyright (c) 2012年 bestone. All rights reserved.
//

#import "Utilities.h"


@implementation Utilities


+ (BOOL) hideKeyboard:(UIView*) view {
	if(view.subviews == nil || [view.subviews count] == 0)
		return NO;
	NSArray *views = [view subviews];
	for(int i = 0; i < [views count]; i++)
	{
		if([[views objectAtIndex:i] isFirstResponder])
		{
			[[views objectAtIndex:i] resignFirstResponder];
			return YES;
		}
		else
		{
			if([self hideKeyboard:[views objectAtIndex:i]])
				return YES;
		}
	}
	return NO;
}




+ (NSInteger)containChineseNum:(NSString *)sourceStr
{
    NSStringEncoding encoding = NSUTF8StringEncoding;
    NSInteger count = 0;
    for (int i = 0; i < [sourceStr length]; i++) {
        //unichar c = [sourceStr characterAtIndex:i];
        
        int bytesLeng = [[sourceStr substringWithRange:NSMakeRange(i, 1)] lengthOfBytesUsingEncoding:encoding];
        
        //NSLog(@"testStr[%d]=%@ = %d,%d", i, [sourceStr substringWithRange:NSMakeRange(i, 1)], c, bytesLeng);
        if (bytesLeng == 3) {
            count ++;
        }
    }
    return count;
}

@end
